package com.edu.exam.enums.grading;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 参与者状态枚举
 */
public enum ParticipantStatus implements BaseEnum {

    REGISTERED("REGISTERED", "已注册"),
    ACTIVE("ACTIVE", "活动中"),
    ATTENDED("ATTENDED", "已参加"),
    ABSENT("ABSENT", "缺席"),
    EXCUSED("EXCUSED", "请假"),
    WITHDRAWN("WITHDRAWN", "退出"),
    COMPLETED("COMPLETED", "已完成");

    private final String code;
    private final String description;

    ParticipantStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据代码获取枚举值
     *
     * @param code 代码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果代码无效
     */
    public static ParticipantStatus fromCode(String code) {
        for (ParticipantStatus status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown ParticipantStatus code: " + code);
    }

    /**
     * 根据描述获取枚举值
     *
     * @param description 描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述无效
     */
    public static ParticipantStatus fromDescription(String description) {
        for (ParticipantStatus status : values()) {
            if (status.getDescription().equals(description)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown ParticipantStatus description: " + description);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}